﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RequestCredit.aspx.cs" Inherits="RequestCredit"
    MasterPageFile="~/Site.master" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <br />
    <table >
    
        <tr >
            <td style="width: 250px;">
                <asp:Label ID="CreditLabel"  runat="server" Text="Кредит:" AssociatedControlID="CreditList"></asp:Label>
            </td>
            <td>
                <asp:DropDownList ID="CreditList" Width="250" runat="server" DataSourceID="SqlDataSourceCredit"
                    DataTextField="Name" DataValueField="CreditID" OnDataBound="CreditList_DataBound"
                    OnSelectedIndexChanged="CreditList_SelectedIndexChanged" AutoPostBack="true">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSourceCredit" runat="server" ConnectionString="<%$ ConnectionStrings:BankDBConnectionString %>"
                    SelectCommand="SELECT [Name], [CreditID] FROM [Credit] WHERE ([Active] = @Active)">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="true" Name="Active" Type="Boolean" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
        </tr>
        <%--// Валидаторы на срок кредита--%>
        <tr>
            <td >
                <asp:Label ID="TermLabel" runat="server" Text="На срок:"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TermLength" MaxLength="3" Width="244" runat="server"></asp:TextBox>
                
                 <asp:RequiredFieldValidator ID="TermLenghtValidator" runat="server" ControlToValidate="TermLength"
                        CssClass="failureNotification" ErrorMessage="Введите телефон" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
                
                <asp:RangeValidator ID="RangeValidatorTermLength" runat="server" Text="Неверно задан срок (1-900)"
                    ControlToValidate="TermLength" Type="Integer" ForeColor="Red" MinimumValue="1" MaximumValue="900" ValidationGroup="RequestCreditValidationGroup"></asp:RangeValidator>

               
                    </td>
                 <%--   <td>
                <asp:RequiredFieldValidator ID="TermLenghtValidator" ControlToValidate="TermLength"
                    Text="*" ForeColor="Red" SetFocusOnError="true" runat="server" ValidationGroup="RequestCreditValidationGroup"></asp:RequiredFieldValidator>
            </td>--%>
        </tr>
        <%--  // Валидаторы на сумму--%>
        <tr>
            
                <td>
                    <asp:Label ID="AmountLabel" runat="server" Text="Сумма:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="Amount" MaxLength="12" runat="server" Width="244"></asp:TextBox>

                  <%--  <asp:RequiredFieldValidator ID="RangeValidatorAmount2" ControlToValidate="Amount"
                        Text="*" ForeColor="Red" SetFocusOnError="true" runat="server" ValidationGroup="RequestCreditValidationGroup"></asp:RequiredFieldValidator>--%>

                      <asp:RequiredFieldValidator ID="RangeValidatorAmount2" runat="server" ControlToValidate="Amount"
                        CssClass="failureNotification" ErrorMessage="Введите сумму" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
           
         
                <asp:RangeValidator ID="RangeValidatorAmount" Width="244" runat="server" Text="Неверно указана сумма"
                    ControlToValidate="Amount" Type="Integer" ForeColor="Red" MinimumValue="1" MaximumValue="9999"
                    ValidationGroup="RequestCreditValidationGroup" Display="Dynamic"></asp:RangeValidator>
         
            <br />
            <asp:DropDownList ID="CurrencyList"  runat="server" DataSourceID="SqlDataSourceCurrency"
                DataTextField="Name" DataValueField="CurrencyID" Width="250" AutoPostBack="True" 
                        onselectedindexchanged="CurrencyList_SelectedIndexChanged">
            </asp:DropDownList>
            </td>
        </tr>
        <asp:SqlDataSource ID="SqlDataSourceCurrency" runat="server" ConnectionString="<%$ ConnectionStrings:BankDBConnectionString %>"
            SelectCommand="SELECT Currency.Name, CreditCurrency.CurrencyId AS CurrencyID FROM Currency INNER JOIN CreditCurrency ON Currency.CurrencyID = CreditCurrency.CurrencyId WHERE (CreditCurrency.CreditId = @CreditId)">
            <SelectParameters>
                <asp:ControlParameter ControlID="CreditList" PropertyName="SelectedValue" Type="Int32"
                    Name="CreditId" DefaultValue="0" />
            </SelectParameters>
        </asp:SqlDataSource>
        <tr>
            <td>
                <asp:Label ID="FormLabel" runat="server" Text="Форма выдачи:"></asp:Label>
            </td>
            <td>
                <asp:DropDownList ID="CreditFacilitiesFormList" Width="250" runat="server" DataSourceID="SqlDataSourceForm"
                    DataTextField="Name" DataValueField="CreditFacilitiesFormId">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSourceForm" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
                    SelectCommand="SELECT CreditFacilitiesForm.CreditFacilitiesFormId, CreditFacilitiesForm.Name FROM CreditFacilitiesForm INNER JOIN CreditCreditFacilitiesForm ON CreditFacilitiesForm.CreditFacilitiesFormId = CreditCreditFacilitiesForm.CreditFacilitiesFormId INNER JOIN Credit ON CreditCreditFacilitiesForm.CreditId = Credit.CreditID WHERE (Credit.CreditID = @CreditId)">
                    <SelectParameters>
                        <asp:Parameter Name="CreditId" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
        </tr>
        <%--  // Валидатор на название--%>
        <tr>
            <td>
                <asp:Label ID="CompanyNameLabel" runat="server" Text="Название предприятия"></asp:Label>
            </td>
            <td>
                <asp:TextBox MaxLength="50" ID="CompanyName" runat="server" Width="244" OnTextChanged="CompanyName_TextChanged"
                    AutoPostBack="true"></asp:TextBox>
                <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="CompanyName"
                    MinimumPrefixLength="1" CompletionInterval="10" CompletionSetCount="3" UseContextKey="True"
                    ServiceMethod="GetCompletionList" DelimiterCharacters="" Enabled="True" ServicePath="">
                </asp:AutoCompleteExtender>
               <%-- <asp:RequiredFieldValidator ID="CompanyNameValidator" ControlToValidate="CompanyName"
                    Text="*" ForeColor="Red" SetFocusOnError="true" runat="server" ValidationGroup="RequestCreditValidationGroup"></asp:RequiredFieldValidator>--%>
                 <asp:RequiredFieldValidator ID="CompanyNameValidator2" runat="server" ControlToValidate="CompanyName"
                        CssClass="failureNotification" ErrorMessage="Введите адресс" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
                        
                         <asp:RegularExpressionValidator ID="CompanyNameValidator3" ControlToValidate="CompanyName"
                    Text="Введите название (2-50)" ForeColor="Red" Display="Dynamic" ValidationExpression="^([a-zA-ZА-Яа-я0-9 '-_&,().]{2,50})+$"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />

            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="OrganizationFormLabel" runat="server" Text="Организационная форма"></asp:Label>
            </td>
            <td>
                <asp:DropDownList Width="250" ID="OrganizationForm" runat="server" DataSourceID="SqlDataSourceOrgatizationalForm"
                    DataTextField="Name" DataValueField="CompanyOrganizationalFormId" OnDataBound="OrganizationForm_DataBound"
                    Enabled="false">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSourceOrgatizationalForm" runat="server" ConnectionString="<%$ ConnectionStrings:BankDBConnectionString %>"
                    SelectCommand="SELECT [Name], [CompanyOrganizationalFormId] FROM [OrganizationalForm]">
                </asp:SqlDataSource>
            </td>
        </tr>
        <%--// Валидаторы на ФИО с регулярками!--%>
        <tr>
           
                <td>
                    <asp:Label ID="HeadNameLabel" runat="server" Text="Ф.И.О. руководителя"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="HeadName" MaxLength="50" Width="244" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="HeadNamevalidator1" runat="server" ControlToValidate="HeadName"
                        CssClass="failureNotification" ErrorMessage="Введите ФИО" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
           
          <asp:RegularExpressionValidator ID="HeadnameValidator2" ControlToValidate="HeadName"
                    Text="Неправильный формат записи ФИО" ForeColor="Red" Display="Dynamic" ValidationExpression="^[А-ЯЁ][а-яё]{1,}(([ ]|[-])([А-ЯЁ]|[а-яё]){1}[а-яё]{1,})*$"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />
            
            </td>
        </tr>
        <%--// Валидаторы с регулярками на телефон руководителя--%>
        <tr>
            
                <td>
                    <asp:Label ID="Label1" runat="server" Text="Телефон руководителя"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="HeadPhone" MaxLength="12" Width="244" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="HeadPhoneValidator" runat="server" ControlToValidate="HeadPhone"
                        CssClass="failureNotification" ErrorMessage="Введите телефон" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
           
            
                <asp:RegularExpressionValidator ID="HeadPhoneValidator2" ControlToValidate="HeadPhone"
                    Text="Неправильный формат тел. номера" ForeColor="Red" Display="Dynamic" ValidationExpression="[1-9]{1}[0-9]{6,12}"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" Font-Bold="False" />
            
            </td>
        </tr>
        <%--// Валидаторы на адресс руководителя!--%>
        <tr>
            <td>
                <asp:Label ID="Label2" runat="server" Text="Адрес руководителя"></asp:Label>
            </td>
            <td>
                <asp:TextBox MaxLength="100" ID="HeadAddress" Width="244" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="HeadAdressValidator1" runat="server" ControlToValidate="HeadAddress"
                    CssClass="failureNotification" ErrorMessage="Введите адресс" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
                 <asp:RegularExpressionValidator ID="HeadAdressValidator2" ControlToValidate="HeadAddress"
                    Text="Неправильный формат записи адреса (7-100)" ForeColor="Red" Display="Dynamic" ValidationExpression="^([a-zA-ZА-ЯЁа-яё0-9 !'-_&,().]{2,50})+$"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />
            </td>
        </tr>
        <%--// Валидаторы на адресс предприятия!--%>
        <tr>
            <td>
                <asp:Label ID="CompanyAddressLabel" runat="server" Text="Адрес предприятия"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="CompanyAddress" MaxLength="100" Width="244" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="CompanyAddressValidator" runat="server" ControlToValidate="CompanyAddress"
                        CssClass="failureNotification" ErrorMessage="Введите адресс" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
                         <asp:RegularExpressionValidator ID="CompanyAdressValidator1" ControlToValidate="CompanyAddress"
                    Text="Неправильный формат записи адреса (7-100)" ForeColor="Red" Display="Dynamic" ValidationExpression="^([a-zA-ZА-ЯЁа-яё0-9 !'-_&,().]{7,50})+$"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />

            </td>
        </tr>
        <%-- // // Валидаторы на телефон предприятия!--%>
        <tr>
            
                <td>
                    <asp:Label ID="CompanyPhoneLabel" runat="server" Text="Телефон предприятия"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="CompanyPhone" MaxLength="12" Width="244" runat="server" 
                        ToolTip="Введите номер (городской, областной, мобильный) без использования доп.символов!"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="CompanyPhoneValidator" runat="server" ControlToValidate="CompanyPhone"
                        CssClass="failureNotification" ErrorMessage="Введите телефон" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
            
            
                <asp:RegularExpressionValidator ID="CompanyPhoneValidator2" ControlToValidate="CompanyPhone"
                    Text="Неправильный формат тел. номера" ForeColor="Red" Display="Dynamic" 
                    ValidationExpression="[1-9]{1}[0-9]{6,12}"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />
            
            </td>
        </tr>
        <%--// Валидаторы на мыло--%>
        <tr>
            
                <td>
                    <asp:Label ID="CompanyEmailLabel" runat="server" Text="Email предприятия"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="CompanyEmail" MaxLength="50" Width="244" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="OperatorEmailValidator" runat="server" ControlToValidate="CompanyEmail"
                        CssClass="failureNotification" ErrorMessage="Введите e-mail" ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
            
            
                <asp:RegularExpressionValidator ID="OperatorEmailValidator2" ControlToValidate="CompanyEmail"
                    Text="Неправильный формат записи Email. Повторите ввод." ForeColor="Red" ValidationExpression="^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />
            
            </td>
        </tr>
        <%--// Валидаторы на доход--%>
        <tr>
            <td>
                <asp:Label ID="CompanyProfitLabel" runat="server" Text="Доход предприятия за последние 2 года"></asp:Label>&nbsp;(или
                менее, если предприятие существует меньший срок)
            </td>
            <td>
                <asp:TextBox ID="CompanyProfit" MaxLength="12" Width="244" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="CompanyProfitValidator" runat="server" ControlToValidate="CompanyProfit"
                CssClass="failureNotification" ToolTip="CompanyProfit is required." ValidationGroup="RequestCreditValidationGroup">*</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="CompanyProfitValidator1" ControlToValidate="CompanyProfit"
                    Text="Введите целое положительное число" ForeColor="Red" Display="Dynamic" ValidationExpression="[1-9]{1}[0-9]{1,12}"
                    runat="server" ValidationGroup="RegisterUserValidationGroup" Font-Bold="False" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="HaveCreditLabel" runat="server" Text="Наличие кредитов"></asp:Label>
            </td>
            <td>
                <asp:CheckBox ID="HaveCredit" Width="244" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="UserCommentAboutDateLabel" runat="server" Text="Напишите удобное для вас время прихода в банк (день недели, время)"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="UserCommentAboutDate" MaxLength="100"  runat="server" TextMode="MultiLine" Height="73px"
                    Width="244px"></asp:TextBox>
                 <asp:RegularExpressionValidator ID="UserCommentAboutDateValidator" ControlToValidate="UserCommentAboutDate"
                    Text="Введите ваш комментарий (5-50)" ForeColor="Red" Display="Dynamic" ValidationExpression="^([a-zA-ZА-Яа-я0-9 '-_&:;,().]{2,50})+$"
                    runat="server" ValidationGroup="RequestCreditValidationGroup" />

            </td>
        </tr>
    </table>
    <br />
    <asp:Button ID="RequestCreditButton" runat="server" Text="Отправить запрос" ValidationGroup="RequestCreditValidationGroup"
        OnClick="RequestCreditButton_Click" />
    <asp:Label ID="ErrorLabel" runat="server" Text=""></asp:Label>
</asp:Content>
